package org.rsbot.script.methods;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class Hiscores extends MethodProvider
{
  private static final String HOST = "http://hiscore.runescape.com";
  private static final String GET = "/index_lite.ws?player=";

  public Hiscores()
  {
    super(null);
  }

  public Stats lookup(String paramString)
  {
    if ((paramString != null) && (!paramString.isEmpty()))
      try {
        URL localURL = new URL("http://hiscore.runescape.com/index_lite.ws?player=" + paramString);
        BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localURL.openStream()));

        int[] arrayOfInt1 = new int[26];
        int[] arrayOfInt2 = new int[26];
        int[] arrayOfInt3 = new int[26];
        for (int i = 0; i < 26; i++) {
          String[] arrayOfString = localBufferedReader.readLine().split(",");
          arrayOfInt1[i] = Integer.parseInt(arrayOfString[2]);
          arrayOfInt2[i] = Integer.parseInt(arrayOfString[1]);
          arrayOfInt3[i] = Integer.parseInt(arrayOfString[0]);
        }
        localBufferedReader.close();
        return new Stats(paramString, arrayOfInt1, arrayOfInt2, arrayOfInt3);
      }
      catch (IOException localIOException) {
      }
    return null;
  }
  public static class Stats {
    private String username;
    private int[] exps;
    private int[] lvls;
    private int[] ranks;

    Stats(String paramString, int[] paramArrayOfInt1, int[] paramArrayOfInt2, int[] paramArrayOfInt3) { this.username = paramString;
      this.exps = paramArrayOfInt1;
      this.lvls = paramArrayOfInt2;
      this.ranks = paramArrayOfInt3;
    }

    public int getExperience(int paramInt)
    {
      if ((paramInt < 0) || (paramInt >= this.exps.length - 1)) {
        throw new IllegalArgumentException(new StringBuilder().append("Illegal skill index: ").append(paramInt).toString());
      }
      return this.exps[(paramInt + 1)];
    }

    public int getLevel(int paramInt)
    {
      if ((paramInt < 0) || (paramInt >= this.exps.length - 1)) {
        throw new IllegalArgumentException(new StringBuilder().append("Illegal skill index: ").append(paramInt).toString());
      }
      return this.lvls[(paramInt + 1)];
    }

    public int getRank(int paramInt)
    {
      if ((paramInt < 0) || (paramInt >= this.exps.length - 1)) {
        throw new IllegalArgumentException(new StringBuilder().append("Illegal skill index: ").append(paramInt).toString());
      }
      return this.ranks[(paramInt + 1)];
    }

    public int getOverallExp()
    {
      return this.exps[0];
    }

    public int getOverallLevel()
    {
      return this.lvls[0];
    }

    public int getOverallRank()
    {
      return this.ranks[0];
    }

    public String getUsername()
    {
      return this.username;
    }

    public String toString()
    {
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append(this.username).append("[overall:");
      localStringBuilder.append(this.lvls[0]).append(",").append(this.ranks[0]);
      localStringBuilder.append(",").append(this.exps[0]).append(" ");
      for (int i = 0; i < this.lvls.length - 1; i++) {
        localStringBuilder.append(Skills.SKILL_NAMES[i]).append(":");
        localStringBuilder.append(this.lvls[(i + 1)]).append(",").append(this.ranks[(i + 1)]);
        localStringBuilder.append(",").append(this.exps[(i + 1)]).append(" ");
      }
      return localStringBuilder.toString().replaceFirst("\\s+$", "]");
    }
  }
}